package com.xr.wage.classItem;

import com.xr.common.BusinessTypeVar;
import com.xr.common.CommUtil;
import com.xr.common.DBTools;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;

/**
 * dsListener
 */
public class dsListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
	  String dsName = dataset.parameters().getString("dsName");
		String sql = "";
			SqlDataset ds = (SqlDataset) dataset;
			DoradoContext context = DoradoContext.getContext();
			 
			if(dsName != null && dsName.equals("empClassBankPayer_datasetCBP")) {
				sql=ds.getSql();
				
				if(ds.parameters().getValue("MANAGER_ID")!=null && ds.parameters().getLong("MANAGER_ID")>0){
					sql+=" and nvl(oc.MANAGER_ID,0)="+ds.parameters().getValue("MANAGER_ID");
				}else{
					//sql+=" and nvl(oc.MANAGER_ID,0)="+CommUtil.getEmployeeId();
					sql += CommUtil.getDataRightSql("oos", BusinessTypeVar.wage_classItem_dsListener_empClassBankPayer_datasetCBP);
				}
				
				sql += CommUtil.setConditionSQL(ds)+" "; 
				
				ds.setSql(sql);
				 
			}
			if(dsName != null && dsName.equals("empClassBankPayer_datasetBatchAdd")) {
				sql=ds.getSql();
		 
				if(ds.parameters().getValue("MANAGE_ID")!=null && ds.parameters().getLong("MANAGE_ID")>0){
					sql+=DBTools.getDataRightSql("oos", Integer.parseInt(BusinessTypeVar.wage_classItem_dsListener_empClassBankPayer_datasetCBP),ds.parameters().getLong("MANAGE_ID")+"");
				}else{
				    sql += CommUtil.getDataRightSql("oos", BusinessTypeVar.wage_classItem_dsListener_empClassBankPayer_datasetCBP);
				}
				if(ds.parameters().getString("DEPT_CITY_NAME")!=null && !ds.parameters().getString("DEPT_CITY_NAME").equals("")){
					sql+=" and exists(select 1 from pb_city c where d.city_id=c.city_id and c.city_name like '%"+ds.parameters().getString("DEPT_CITY_NAME")+"%')";
				}
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
			}
			if(dsName != null && dsName.equals("oosClassPlanDropdown_datasetPlan")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" order by ocp.run_order,wage_date "; 
				ds.setSql(sql);
			}
			 
			
    return true;
  }

}
